package com.kongwg.java1;

/**
 * @author kongwg
 * @create 2020-12-05 15:42
 */
public class BankTest {
}

class Bank {
    private Bank() {
    }

    private static Bank instance = null;

    private static Bank getInstance() {

//        synchronized (Bank.class) {
//            if (instance == null) {
//                instance = new Bank();
//            }
//        return instance;
//        }
        //方式二：效率更高
        if (instance == null) {
            synchronized (Bank.class) {
                if (instance == null) {
                    instance = new Bank();
                }
            }
        }
        return instance;
    }
}

